package com.example.interesting.distributed.log.realize.dubbo.consumer;

import com.example.interesting.distributed.log.realize.util.LogTraceInit;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties;

import java.util.Map;

/**
 * @Description: dubbo调用消费者过滤器
 * @Author: fyw
 * @Date: 2024/4/6 17:11
 * @History
 */
public class DubboConsumerFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //获取mdc日志扩展信息，并替换服务名
        Map<String, String> stringStringMap = LogTraceInit.replaceServiceName();
        stringStringMap.forEach(invocation::setAttachment);
        return invoker.invoke(invocation);
    }
}
